package com.crm.web.admin;


import com.crm.result.Result;
import com.crm.service.IndexService;
import com.crm.vo.IndexBaseInfoVO;
import com.crm.vo.IndexStatisticsVo;
import com.crm.vo.IndexTodayInfoVO;
import com.crm.vo.IndexTodoInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.time.LocalDate;
import java.util.List;
import java.util.Map;


/**
 * 首页
 */

@CrossOrigin
@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IndexService indexService;

    @GetMapping("/getBaseInfo")
    public Result getBaseInfo(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endCreateTime
    ){
         IndexBaseInfoVO indexBaseInfoVO=indexService.getBaseInfo(beginCreateTime,endCreateTime);
        return Result.success(indexBaseInfoVO);
    }
    @GetMapping("/getTodayInfo")
    public Result getTodayInfo(){
        IndexTodayInfoVO indexTodayInfoVO=indexService.getTodayInfo();
        return Result.success(indexTodayInfoVO);
    }

    @GetMapping("/getTodoInfo")
    public Result getTodoInfo(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endCreateTime){
        IndexTodoInfoVO indexTodoInfoVO=indexService.getTodoInfo(beginCreateTime,endCreateTime);
        return Result.success(indexTodoInfoVO);
    }
    @GetMapping("/businessChangeStatistics")
    public Result businessChangeStatistics(IndexStatisticsVo indexStatisticsVo)  {
        List<Map<String,Object>> list=indexService.businessChangeStatistics(indexStatisticsVo);
        return Result.success(list);
    }

    @GetMapping("/salesStatistic")
    public Result salesStatistic(IndexStatisticsVo indexStatisticsVo){
        List<Map<String,Object>> list=indexService.salesStatistic(indexStatisticsVo);
        return Result.success(list);
    }
}